// Copyright AO CELL Team 2005-2008 
// Inital Code Set by Nincb - ROUGH  - THE DLL FILE IS NOT MINE, IS NOT MINE UNTIL I WRITE ONE, ITS AN EXAMPLE FROM MICRSOFT

using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;

class NativeMethods
{
    // This is a call to unmanaged code. Without this permission
    // a SecurityException will be subdued:
    [DllImport("msvcrt.dll")]
    public static extern int puts(string str);
    [DllImport("msvcrt.dll")]
	// This will prevent certain RAW codes 
    internal static extern int _flushall();
}

class MainClass
{
    private static void CUCWP()
    {
        // Create a security var or um code
        SecurityPermission perm = 
           new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
        //   IMPORTANT - THE ABOVE MUST NOT CHANGE
		  
        // Without perms:
		
        perm.Deny();

        try
        {
            Console.WriteLine("Attempting to call unmanaged code without permission.");
            NativeMethods.puts("This is where the server will be called. ");
            NativeMethods._flushall();
            Console.WriteLine("Permission Denied");
        }
        catch (SecurityException)
        {
            Console.WriteLine("TRAP: SE On ULA");
        }
    }

    private static void CUMWP()
    {
	    // Only slight changes here
        SecurityPermission perm = 
           new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

       
        perm.Assert();

        try
        {
            Console.WriteLine("Attempting...");
            NativeMethods.puts("Called!");
            NativeMethods._flushall();
            Console.WriteLine("Error");
        }
        catch (SecurityException)
        {
            Console.WriteLine("Error");
        }
    }

    public static void MainSET() 
    {
        // Over-revising
        SecurityPermission perm = new 
            SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
        perm.Assert();
        CallUnmanagedCodeWithoutPermission();

        // See above
        perm.Deny();
        CallUnmanagedCodeWithPermission();
    }
	// El Fin!
	
}

// I am going to link this example into the main code set :)
// Took me a few hours to write this, not too bad.
// - Nincb